/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-08-16 13:46:23
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-08-24 09:07:47
 * @FilePath: \四阶段项目\src\store\workOrderStore.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {makeAutoObservable, toJS} from 'mobx'
import services  from '../service'

class workOrderStore{
    
  constructor(){
    makeAutoObservable(this)
  }
  WorkOrderHeadList=[]; //工单列表数据
  CheckWorkOrderList=[]  //客户名称查看工单数据
  RecordworkOrderList=[]  //工作记录数据
  UpdetaWorkorderList=[]  //修改数据
  SearchWorkOrderList=[]  //搜索按钮数据
  AddBtnworkorderList=[]  //新增按钮里原本数据

  //点击工单列表数据
  findAllWorkOrderList= (currentPage,pageSize)=>{

    return new Promise((resolve,reject)=>{
        services.workOrderService.getAllDataList(currentPage,pageSize).then((data)=>{
               resolve(data)
               this.WorkOrderHeadList=data.data
               console.log(data.data,'WorkOrderHeadList');
        })
    })
  }
  //点击工单列表已完成按钮，工单列表处理中按钮，工单列表未处理按钮数据
  getDataList=(currentPage,pageSize,processing_status)=>{
    return new Promise((resolve,reject)=>{
      services.workOrderService.getDataList(currentPage,pageSize,processing_status).then((data)=>{
        resolve(data)
               this.WorkOrderHeadList=data.data
               console.log(data.data,'getDataList');
      })
    })
  }
    //点击客户名称 处理状态 编辑按钮 数据
  findWorkOrderById= (work_order_id)=>{

    return new Promise((resolve,reject)=>{
        services.workOrderService.getCheckWorkOrderList(work_order_id).then((data)=>{
               
               resolve(data)
                this.CheckWorkOrderList=data.data

        })
    })
  }
  
  //处理状态改变 点击模态框确定 修改数据
  disposeStateList=(work_order_id,processing_status)=>{
      return new Promise((resolve,reject)=>{
       services.workOrderService.disposeState(work_order_id,processing_status).then((data)=>{
        resolve(data)
        console.log(data,'disposeStateList');
  
       })
      })
  }
  //点击工单记录数据
  findWorkRecordById= (work_order_id)=>{
    return new Promise((resolve,reject)=>{
        services.workOrderService.getRecordworkOrderList(work_order_id).then((data)=>{
               console.log(data.data,'getRecordworkOrderList');
               resolve(data)
                this.RecordworkOrderList=data.data
        })
    })
  }

  //点击修改保存按钮数据

  updateWorkOrder=()=>{
     return new Promise((resolve,reject)=>{
      services.workOrderService.updateWorkOrderList().then((data)=>{
        console.log(data,'updateWorkOrderList');
        if(data.code===200){
          this.findAllWorkOrderList(1,5)
        }
        resolve(data)

      })
     })
  }

//点击删除按钮 删除数据
  deleteWorkOrder=(work_order_id,currentPage,pageSize)=>{
    return new Promise((resolve,reject)=>{
       services.workOrderService.deleteWorkOrderList(work_order_id).then((data)=>{
        console.log(data,'deleteWorkOrderList');
        resolve(data)
        if (data.code===null){
         this.findAllWorkOrderList(currentPage,pageSize)
         console.log(123);
        }
     
       })
    })
  }


  //点击我发起的按钮  改变表格数据
  Mystarted=(currentPage,pageSize,user_name)=>{
    return new Promise((resolve,reject)=>{
      services.workOrderService.Mystarted(currentPage,pageSize,user_name).then((data)=>{
        console.log(data.data,'Mystarted');
        resolve(data)
        this.WorkOrderHeadList=data.data
      })
    })
  }
  //点击我参与的按钮  改变表格数据
  Myjoin=(currentPage,pageSize,assigned_personnel)=>{
      return new Promise((resolve,reject)=>{
        services.workOrderService.Myjoin(currentPage,pageSize,assigned_personnel).then((data)=>{
          console.log(data.data,'Myjoin');
          resolve(data)
        this.WorkOrderHeadList=data.data
        })
      })
  }


//点击搜索按钮  展示表格数据
SearchBtn=(currentPage,pageSize,condition)=>{
  return new Promise((resolve,reject)=>{
    services.workOrderService.searchBtn(currentPage,pageSize,condition).then((data)=>{
      console.log(data.data,'SearchBtn');
      resolve(data)
      this.WorkOrderHeadList=data.data
    })
  })
}
//点击新增按钮  展示表格数据
AddBtn=(currentPage,pageSize)=>{
  return new Promise((resolve,reject)=>{
    services.workOrderService.addBtn(currentPage,pageSize).then((data)=>{
      console.log(data.data,'addBtn');
      resolve(data)
      this.AddBtnworkorderList=data.data
    })
  })
}
  
}



//需要 data  

// get data action
export default  workOrderStore